package com.foo.ui_demo_widge;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class ButtonActivity extends AppCompatActivity implements View.OnClickListener {
private Button btndisplay;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button);
        //寻找按钮元素
        findViewById(R.id.btn1).setOnClickListener(this);
        findViewById(R.id.btn2).setOnClickListener(this);
        findViewById(R.id.ib_test3).setOnClickListener(this);
        btndisplay = findViewById(R.id.btn_display);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn1:
            case R.id.btn2:
             btndisplay.setText(((Button)(v)).getText());
             break;
            case R.id.ib_test3:
                btndisplay.setText(((ImageButton)v).getContentDescription());
                break;
        }

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}